/**
 * 提供一个简易的观察者模式对象
 */
class ObserverUtil {
  private innerTextNum = 1
  private hiddenDom = document.createElement('i')
  private observer: MutationObserver
  
  constructor(private callback: Function) {
    this.init()
  }
  
  private init() {
    this.observer = new MutationObserver(() => this.callback())
    this.observer.observe(this.hiddenDom, {characterData: true})
  }
  
  emitChange() {
    this.hiddenDom.innerText = this.innerTextNum++ + ''
  }
}

export default ObserverUtil
